<?php
/**
 * 后台管理基类
 *  
 */
class QController extends FrontController
{
 	public $admin;//最大的管理员
  	public $filter_tag;//标签搜索
	public $filter_user;//用户搜索
 	function init(){
 		parent::init();  
 		//设置module的界面与前台相同，对应FrontController 第16行，设置了theme属性值
		$this->module->layoutPath = $this->theme.'/views/layouts'; 
		if(app()->user->isGuest || app()->user->isadmin !== true)
			throw new CHttpException(403,'您没有足够的权限访问该页面！');
 		//取得当前最大的管理员
 		$model = User::model()->findByPk(1);
 		$this->admin = $model->email;
 		//搜索时需要用到的
 		$this->filter();
 	}
 	/**
 	* admin 过滤
 	*/
 	function filter(){
 		$criteria=new CDbCriteria;
	    $criteria->select = "(tag),id";
	    $criteria->distinct = "tag";
	    $criteria->group = "tag";
	    $tag = News::model()->findAll($criteria); 
	    $this->filter_tag = $this->to_array($tag,'tag','tag');
	    $criteria=new CDbCriteria;
	    $criteria->select = "id,email"; 
	    $criteria->order = "id desc";
	    $criteria->condition ="flag = 1";
	    $tag = User::model()->findAll($criteria); 
	    $this->filter_user = $this->to_array($tag,'id','email');
 	}
 	/**
	 * 对后台theme的设置
	 *
	 */
	protected function theme(){  
		$this->layout = 'main';    
		Yii::app()->themeManager->setBaseUrl(Yii::app()->baseUrl.'/themes/_admin'); 
		Yii::app()->themeManager->setBasePath(Yii::app()->basePath.'/../themes/_admin');   
		app()->theme = 'default'; 
		$this->module->layoutPath = Yii::app()->theme->basePath.'/views/layouts';   
		
	}
	/**
	*
	* 写入日志
	*/
	protected function log($title,$body,$action='read'){
		$model = new Log;
		$model->created = time();
		$model->title = $title;
		$model->body = $body;
		$model->action = $action;
		$model->uid = user('id');
		$model->save();
	}
}